package com.cn.springcloudwechat.controller.order;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.mybatis.Page;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.model.order.YmOrder;
import com.cn.springcloudwechat.model.order.YmOrderGoods;
import com.cn.springcloudwechat.service.order.YmOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单及商品详情Controller
 * @author: Administrator
 * @create: 2018/7/31 17:57
 */

@RestController
@RequestMapping(value = "/web/oder/")
public class YmOrderControllerWeb {

    @Autowired
    YmOrderService ymOrderService;

    /**
     * 批量获取数据
     *
     * @param ajaxRes
     * @param ymOrder
     * @param page
     * @return
     */
    @GetMapping("getAllYmOrder")
    public AjaxRes getAllYmOrder(AjaxRes ajaxRes, YmOrder ymOrder, Page<Object> page) {
        Page<Object> ymOrders = ymOrderService.getAllYmOrder(ymOrder,page);
        ajaxRes.setSucceed(ymOrders);
        return ajaxRes;
    }

    /**
     * 批量获取商品数据
     *
     * @param ajaxRes
     * @param ymOrderGoods
     * @param page
     * @return
     */
    @GetMapping("getAllYmOrderGoods")
    public AjaxRes getAllYmOrderGoods(AjaxRes ajaxRes, YmOrderGoods ymOrderGoods, Page<Object> page) {
        Page<Object> ymOrderGoodsList = ymOrderService.getAllYmOrderGoods(ymOrderGoods,page);
        ajaxRes.setSucceed(ymOrderGoodsList);
        return ajaxRes;
    }

    /**
     * 添加订单及商品详情数据
     *
     * @param ajaxRes
     * @param ymOrderGoods
     * @param ymOrder
     * @return
     */
    @PostMapping("insertYmOrderGoodsAndYmOrder")
    public AjaxRes insertYmOrderGoodsAndYmOrder(AjaxRes ajaxRes, YmOrderGoods ymOrderGoods, YmOrder ymOrder) {
        Long orderId= ymOrderService.insertYmOrderGoodsAndYmOrder(ymOrder, ymOrderGoods);
        ajaxRes.setSucceed(orderId);
        return ajaxRes;
    }

    /**
     * 更新商品数据
     *
     * @param ajaxRes
     * @param ymOrderGoods
     * @return
     */
    @PostMapping("updateYmOrderGoods")
    public AjaxRes updateYmOrderGoods(AjaxRes ajaxRes, YmOrderGoods ymOrderGoods) {
        ymOrderService.updateYmOrderGoods(ymOrderGoods);
        ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
        return ajaxRes;
    }

    /**
     * 更新订单数据
     *
     * @param ajaxRes
     * @param ymOrder
     * @return
     */
    @PostMapping("updateYmOrder")
    public AjaxRes updateYmOrder(AjaxRes ajaxRes, YmOrder ymOrder) {
        ymOrderService.updateYmOrder(ymOrder);
        ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
        return ajaxRes;
    }

    /**
     * 根据订单id查询单个订单数据
     *
     * @param ajaxRes
     * @param orderId
     * @return
     */
    @GetMapping("getYmOrder")
    public AjaxRes getYmOrder(AjaxRes ajaxRes, @RequestParam long orderId) {
        YmOrder ymOrder = ymOrderService.getYmOrder(orderId);
        ajaxRes.setSucceed(ymOrder);
        return ajaxRes;
    }

    /**
     * 根据商品详情id查询单个商品详情数据
     *
     * @param ajaxRes
     * @param goodsIdDesc
     * @return
     */
    @GetMapping("getYmOrderGoods")
    public AjaxRes getYmOrderGoods(AjaxRes ajaxRes, @RequestParam long goodsIdDesc) {
        YmOrderGoods ymOrderGoods = ymOrderService.getYmOrderGoods(goodsIdDesc);
        ajaxRes.setSucceed(ymOrderGoods);
        return ajaxRes;
    }

    /**
     * 根据订单id查询商品详情
     * @param ajaxRes
     * @param orderId
     * @return
     */
    @GetMapping("getOrderGoodsByOrderId")
    public AjaxRes getOrderGoodsByOrderId(AjaxRes ajaxRes, @RequestParam long orderId){
        List<YmOrderGoods>ymOrderGoods= ymOrderService.getOrderGoodsByOrderId(orderId);
        ajaxRes.setSucceed(ymOrderGoods);
        return ajaxRes;
    }

}
